use actix_web::{error::ErrorInternalServerError, web, Responder, Result};

use crate::{
    api_get, api_get_in_page, api_get_relevant, api_get_relevant_in_page,
    config::get_page_size,
    database::DbPool,
    route::form::path::{PageForm, SlugForm, SlugPageForm},
    service::class,
};

pub fn config_api_tag(cfg: &mut web::ServiceConfig) {
    cfg.service(
        web::scope("/tag")
            .route("/page/{page}", web::get().to(get_tags))
            .service(
                web::scope("/{slug}")
                    .route("/info", web::get().to(get_tag))
                    .route("/link", web::get().to(get_tag_links))
                    .route("/post/{page}", web::get().to(get_tag_posts))
                    .route("/relevant/{page}", web::get().to(get_relevant_tags)),
            ),
    );
}

api_get!(get_tag, SlugForm, class::tag::get_by_slug);
api_get_in_page!(get_tags, PageForm, class::tag::get_in_page);
api_get_relevant!(get_tag_links, SlugForm, class::link::get_by_tag_slug);
api_get_relevant_in_page!(
    get_tag_posts,
    SlugPageForm,
    class::post::get_in_page_by_tag_slug
);
api_get_relevant_in_page!(
    get_relevant_tags,
    SlugPageForm,
    class::tag::get_in_page_by_tag_slug
);
